package com.tucy.logistics.modules.organization.controller;

import com.tucy.logistics.common.entity.organization.OrganizationBusinessDepartment;
import com.tucy.logistics.common.result.Result;
import com.tucy.logistics.modules.organization.service.OrganizationBusinessDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * author: tcy
 * createDate: 2023/9/15
 * description: 物流营业部
 */
@Api(tags = "物流机构")
@RestController
@RequestMapping("/businessDepartment")
public class OrganizationBusinessDepartmentController {

    @Autowired
    OrganizationBusinessDepartmentService departmentService;

    @ApiOperation(value = "新增修改营业部")
    @PostMapping("/saveOrUpdateBusiness")
    public Result<Boolean> saveOrUpdateBusiness(@RequestBody OrganizationBusinessDepartment department) {
        return Result.success(departmentService.saveOrUpdateBusiness(department));
    }

    @ApiOperation(value = "查询营业部")
    @PostMapping("/queryBusiness")
    public Result<List<OrganizationBusinessDepartment>> queryBusiness() {
        return Result.success(departmentService.queryBusiness());
    }

    @ApiOperation(value = "营业部详情")
    @GetMapping("/queryBusinessDetails/{id}")
    public Result<OrganizationBusinessDepartment> queryBusinessDetails(@PathVariable("id") String id) {
        return Result.success(departmentService.queryBusinessDetails(id));
    }

    @ApiOperation(value = "删除营业部")
    @GetMapping("/deleteBusiness/{id}")
    public Result<Boolean> deleteBusiness(@PathVariable("id") String id) {
        return Result.success(departmentService.deleteBusiness(id));
    }

    @ApiOperation(value = "查询父类机构")
    @GetMapping("/queryParentBusiness/{type}")
    public Result<List<OrganizationBusinessDepartment>> queryParentBusiness(@PathVariable("type") String type) {
        return Result.success(departmentService.queryParentBusiness(type));
    }

    @ApiOperation(value = "增改机构范围")
    @PostMapping("/saveUpdateBusinessRange")
    public Result<Boolean> saveUpdateBusinessRange(@RequestBody OrganizationBusinessDepartment department) {
        return Result.success(departmentService.saveUpdateBusinessRange(department));
    }

    @ApiOperation(value = "删除机构范围")
    @DeleteMapping("/deleteBusinessRange/{id}")
    public Result<Boolean> deleteBusinessRange(@PathVariable("id") String id) {
        return Result.success(departmentService.deleteBusinessRange(id));
    }

    @ApiOperation(value = "导出营业机构")
    @PostMapping("/exportBusiness")
    public void exportBusiness(HttpServletResponse response) throws Exception {
        departmentService.exportBusiness(response);
    }
}
